package com.amado.course33;

import java.util.*;
import java.util.Map.Entry;

/**
 * 对hashMap进行排序
 * Created by Administrator on 2018/7/21.
 */
public class TreeMapTest {
    public static void main(String[] args) {
        Map<String,Integer> map = new TreeMap();
        map.put("a", 3);
        map.put("b", 1);
        map.put("c", 4);
        for(Entry<String, Integer> entry:map.entrySet()){
        	System.out.println(entry.getKey()+"  "+entry.getValue());
        }
        List<Entry<String, Integer>> list = new ArrayList(map.entrySet());
        Collections.sort(list, new Comparator<Entry<String, Integer>>() {
			@Override
			public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
				return o2.getValue()-o1.getValue();
			}
		});
        System.out.println("-0--------------");
        for(Entry<String, Integer> entry:list){
        	System.out.println(entry.getKey()+"  "+entry.getValue());
        }
    }
}

